<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { 
  Key, 
  Refresh, 
  Monitor, 
  Cpu, 
  Platform, 
  Connection, 
  Link 
} from '@element-plus/icons-vue'
import type { SystemInfo } from '../types/electron'

const systemInfo = ref<SystemInfo | null>(null)
const loading = ref(false)

const getSystemInfo = async () => {
  loading.value = true
  
  try {
    const info = await window.api.getSystemInfo()
    systemInfo.value = info
    ElMessage.success('系统信息获取成功')
  } catch (err) {
    ElMessage.error('获取系统信息失败: ' + (err as Error).message)
    console.error('获取系统信息失败:', err)
  } finally {
    loading.value = false
  }
}

// 窗口控制功能
const minimizeWindow = () => {
  window.electron.ipcRenderer.send('window-minimize')
}

const toggleMaximize = () => {
  window.electron.ipcRenderer.send('window-maximize')
}

const closeWindow = () => {
  window.electron.ipcRenderer.send('window-close')
}

onMounted(() => {
  getSystemInfo()
})
</script>

<template>
  <div class="system-info-container">
    <!-- 自定义标题栏 -->
    <div class="custom-titlebar">
      <div class="titlebar-content">
        <div class="app-title">
          <el-icon class="app-icon"><Key /></el-icon>
          <span>设备唯一标识符</span>
        </div>
        <div class="window-controls">
          <button class="control-btn minimize-btn" @click="minimizeWindow" title="最小化">
            <span>−</span>
          </button>
          <button class="control-btn maximize-btn" @click="toggleMaximize" title="最大化">
            <span>□</span>
          </button>
          <button class="control-btn close-btn" @click="closeWindow" title="关闭">
            <span>×</span>
          </button>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 操作区域 -->
      <div class="action-section">
        <div class="action-content">
          <div class="title-section">
            <h1 class="main-title">系统唯一标识符</h1>
            <p class="subtitle">快速获取设备硬件和系统信息</p>
          </div>
          <el-button 
            type="primary" 
            @click="getSystemInfo" 
            :loading="loading"
            size="large"
            class="action-button"
          >
            <el-icon v-if="!loading"><Refresh /></el-icon>
            {{ loading ? '获取中...' : '获取系统信息' }}
          </el-button>
        </div>
      </div>

      <!-- 信息展示区域 -->
      <div class="info-section">
        <div v-if="systemInfo" class="system-info">
          <el-card class="info-card" shadow="hover">
            <template #header>
              <div class="card-header">
                <el-icon class="header-icon"><Monitor /></el-icon>
                <span class="header-title">系统信息</span>
                <el-tag type="success" size="small" class="status-tag">已获取</el-tag>
              </div>
            </template>
            <div class="info-grid">
              <div class="info-item">
                <div class="info-label">
                  <el-icon><Key /></el-icon>
                  <span>系统UUID</span>
                </div>
                <div class="info-value uuid-value">
                  {{ systemInfo.systemUuid }}
                </div>
              </div>
              <div class="info-item">
                <div class="info-label">
                  <el-icon><Cpu /></el-icon>
                  <span>系统序列号</span>
                </div>
                <div class="info-value">
                  {{ systemInfo.systemSerial }}
                </div>
              </div>
              <div class="info-item">
                <div class="info-label">
                  <el-icon><Platform /></el-icon>
                  <span>操作系统序列号</span>
                </div>
                <div class="info-value">
                  {{ systemInfo.osSerial }}
                </div>
              </div>
              <div class="info-item">
                <div class="info-label">
                  <el-icon><Connection /></el-icon>
                  <span>主机名</span>
                </div>
                <div class="info-value">
                  {{ systemInfo.hostname }}
                </div>
              </div>
              <div class="info-item">
                <div class="info-label">
                  <el-icon><Link /></el-icon>
                  <span>完整域名</span>
                </div>
                <div class="info-value">
                  {{ systemInfo.fqdn }}
                </div>
              </div>
            </div>
          </el-card>
        </div>
        
        <!-- 空状态 -->
        <div v-else-if="!loading" class="empty-state">
          <el-empty description="点击上方按钮获取系统信息">
            <el-icon class="empty-icon"><Monitor /></el-icon>
          </el-empty>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.system-info-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  overflow: hidden;
  /* 隐藏滚动条但保持滚动功能 */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.system-info-container::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

/* 自定义标题栏 */
.custom-titlebar {
  height: 40px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  -webkit-app-region: drag;
  display: flex;
  align-items: center;
  z-index: 1000;
}

.titlebar-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 16px;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.app-icon {
  color: #667eea;
  font-size: 16px;
}

.window-controls {
  display: flex;
  gap: 2px;
  -webkit-app-region: no-drag;
}

.control-btn {
  width: 32px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
}

.control-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

.close-btn:hover {
  background: #ff4757;
  color: white;
}

/* 主要内容区域 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0;
}

/* 操作区域 */
.action-section {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: 32px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.action-content {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.title-section {
  flex: 1;
}

.main-title {
  margin: 0 0 8px 0;
  color: white;
  font-size: 28px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
  margin: 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 16px;
  font-weight: 400;
}

.action-button {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
  transition: all 0.3s ease;
}

.action-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

/* 信息展示区域 */
.info-section {
  flex: 1;
  padding: 32px 24px;
  overflow-y: auto;
  /* 隐藏滚动条但保持滚动功能 */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.info-section::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

.system-info {
  max-width: 800px;
  margin: 0 auto;
}

.info-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.info-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
}

.card-header .header-icon {
  font-size: 20px;
  color: #667eea;
  margin-right: 8px;
}

.header-title {
  font-weight: 600;
  color: #333;
  font-size: 18px;
  flex: 1;
}

.status-tag {
  margin-left: auto;
}

/* 信息网格 */
.info-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  background: rgba(102, 126, 234, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(102, 126, 234, 0.1);
  transition: all 0.3s ease;
}

.info-item:hover {
  background: rgba(102, 126, 234, 0.1);
  transform: translateX(4px);
}

.info-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #555;
  font-size: 14px;
}

.info-label .el-icon {
  color: #667eea;
  font-size: 16px;
}

.info-value {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-size: 14px;
  color: #333;
  word-break: break-all;
  line-height: 1.5;
  padding: 8px 12px;
  background: white;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.uuid-value {
  color: #667eea;
  font-weight: 500;
}

/* 空状态 */
.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
}

.empty-icon {
  font-size: 48px;
  color: rgba(255, 255, 255, 0.5);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .action-content {
    flex-direction: column;
    text-align: center;
  }
  
  .main-title {
    font-size: 24px;
  }
  
  .info-section {
    padding: 16px;
  }
}

/* 隐藏滚动条 */
.main-content {
  /* 隐藏滚动条但保持滚动功能 */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.main-content::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}
</style>
